package com.itheima.dao;

import com.itheima.model.domain.Article;
import com.itheima.model.domain.Comment;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author 江梅铭
 * @date 10/28/2023 4:59 PM
 */
@Mapper
public interface CommentMapper {
    // 分页展示某个文章的评论
    @Select("SELECT * FROM t_comment WHERE article_id=#{aid} ORDER BY id DESC")
    public List<Comment> selectCommentWithPage(Integer aid);
    // 后台查询最新几条评论
    @Select("SELECT * FROM t_comment ORDER BY id DESC")
    public List<Comment> selectNewComment();
    // 站点服务统计，统计评论数量
    @Select("SELECT COUNT(1) FROM t_comment")
    public Integer countComment();
    // 通过文章id删除评论信息
    @Delete("DELETE FROM t_comment WHERE id=#{aid}")
    public int deleteCommentWithId(Integer aid);

    @Insert("INSERT INTO t_comment (article_id,created,author,ip,content)" +
            " VALUES (#{articleId}, #{created},#{author},#{ip},#{content})")
    public void pushComment(Comment comment);
    @Select("SELECT * FROM t_comment WHERE id=#{id}")
    Comment selectById(int id);

    @Update("update t_comment SET content = #{content} where id=#{id}")
    int update(int id, String content);
}
